from PyQt4 import QtCore, QtGui
import MySQLdb

#Customizable Class Area#
class labelBtn(QtGui.QLabel):
    def __init__(self, parent, img1):
        super(labelBtn,self).__init__(parent)
        self.img1=img1
#        self.img2=img2
        self.setPixmap(self.img1)
    def mousePressEvent(self, event):
        if event.buttons()==QtCore.Qt.LeftButton:
            self.emit(QtCore.SIGNAL("pressed()"))
#    def mouseReleaseEvent(self, event):
#        self.setPixmap(self.img1)
#        self.emit(QtCore.SIGNAL("released()"))

class DB_Operating():
    def __init__(self,host="localhost",user="root",passwd="123456",db="sakila", charset="utf8",sql=""):
        try:
            conn = MySQLdb.connect(host=host,user=user,passwd=passwd,db=db, charset=charset )
            self.cur = conn.cursor()
            self.cur.execute(sql)    
        except:
            return MessageBox(title='Notes',message='Your information has not been submitted successfully, please check your data connection, then try again !')
        else:
            self.row = self.cur.fetchall()
            conn.commit()
        finally:
            self.cur.close()
            conn.close()
       
class MessageBox(QtGui.QWidget):
    def __init__(self, parent=None,title='message box',message="What do you want to mention ?"):
        QtGui.QWidget.__init__(self, parent)
        self.title=title
        self.message=message
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle(title)
#        reply = QtGui.QMessageBox.question(self, self.title,self.message, QtGui.QMessageBox.Yes)    #, QtGui.QMessageBox.No)
        reply = QtGui.QMessageBox.warning(self, self.title,self.message, QtGui.QMessageBox.Close)    #QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel) 
        if reply == QtGui.QMessageBox.Close:
            self.close()
        

    
    
    
    




